package com.atguigu.serviceedu.controller;


import com.atguigu.commonutils.R;
import com.atguigu.serviceedu.entity.chaptervo.ChapterInfoVo;
import com.atguigu.serviceedu.service.EduChapterService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author xuan
 * @since 2020-04-13
 */
@Api(description="章节管理")
@CrossOrigin
@RestController
@RequestMapping("edu/chapter")
public class EduChapterController {

    @Autowired
    EduChapterService chapterService;

    @PostMapping("addChapter")
    public R addChapter(@RequestBody ChapterInfoVo chapter){
        boolean status = chapterService.editChapter(chapter);
        return status?R.ok():R.error();
    }
    @PutMapping("updateChapter")
    public R updateChapter(@RequestBody ChapterInfoVo chapter){
        boolean status = chapterService.editChapter(chapter);
        return status?R.ok():R.error();
    }
    @DeleteMapping("deleteChapter/{chapterId}")
    public R deleteChapter(@PathVariable("chapterId") String chapterId){
        boolean status = chapterService.deleteChapter(chapterId);
        return status?R.ok():R.error();
    }
    @GetMapping("getChapterList/{courseId}")
    public R getChapterList(@PathVariable("courseId") String courseId){
        List<ChapterInfoVo> chapterList = chapterService.getChapterList(courseId);
        return R.ok().data("chapterList",chapterList);
    }

}

